auto();
threads.start(function () {

   while (true) {

       click("立即开始")

      
       sleep(500)
   }
});
requestScreenCapture();
var 免费领花币 = "240541527439405056";

var 领听书会员 = "370895370772901888";
var 免费领会员 ="413348785930936320"




launchPackage ("com.android.mediacenter");
sleep(1000);
    if(text("同意").findOne(10000)){
        click("同意")
   }
领会员();
听书会员();
领花币();


/*****************领取花币*****************************/

var 华为账号;
var coin;
var 花币领取数量 = 0;


launchApp("设置")
sleep(2000)
点击文字("华为帐号、付款与账单、云空间等");
console.log("打开个人中心");
sleep(10000)
华为帐号 = textContains("华为帐号").findOne(3000);
if(华为帐号){
    华为帐号=华为帐号 .text()
}
console.log(华为帐号);
sleep(3000)
点击文字("付款与账单")
sleep(10000)
var balance =  textEndsWith("花币").untilFind();
if(balance){
    balance=balance[1]
}
coin = balance.text().split("花币")[0];
花币领取数量 = (parseFloat(coin) - 花币领取数量).toFixed(2);
var x = balance.bounds().centerX()
var y = balance.bounds().centerY()
console.log("花币数量" + balance.text());
click(x, y);
sleep(2000);
点击文字("福利大放送");
sleep(10000)
var 领取 = text("领取").find();

if (领取) {
    console.log("找到领取按钮");
    领取.click();
    sleep(10000);
    var 领取 = text("领取").find();
    while (领取.length > 1) {
        text("领取").click();
        sleep(500);
        click("确定");
        sleep(5000)
        领取 = text("领取").find();
    }

}
launchApp("设置")
点击文字("华为帐号、付款与账单、云空间等");

console.log("打开个人中心");

sleep(3000)
点击文字("付款与账单")
sleep(5000)
var balance =  textEndsWith("花币").untilFind();
if(balance){
    balance=balance[1]
}
coin = balance.text().split("花币")[0];
花币领取数量 = (parseFloat(coin) - 花币领取数量).toFixed(2);



微信通知(华为帐号, coin, 花币领取数量)



function 微信通知(华为帐号, coin, 花币领取数量) {
    var wxtxt = 华为帐号 + " 花币余额：" + coin + " 领取花币数量：" + 花币领取数量;
    console.log(wxtxt);
    var getTokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=wwdd06640f29b4ee1a&corpsecret=aDR2ejeBEexnfrL9857hcivIHxTNtNUBvljGPiMUhaw";
    var resp = http.post(getTokenUrl, {});
    var token = resp.body.json()["access_token"];
    var sendMsgUrl = "https://qyapi.weixin.qq.com//cgi-bin/message/send?access_token=" + token;
    res = http.postJson(sendMsgUrl, {
        "touser": "@all",
        "msgtype": "text",
        "agentid": "1000007",
        "text": { "content": wxtxt }
    });
}


    

function 点击文字(文字) {
    sleep(1000);
    var 点击的文字 = textContains(文字).findOne(5000);
    if (点击的文字) {
        var x = 点击的文字.bounds().centerX();
        var y = 点击的文字.bounds().centerY();
        sleep(1000);
        click(x, y);
        console.log("已点击" + 文字);
    } else {
        console.log("未发现" + 文字);
    }

}



try{
//华为音乐签到
app.startActivity({
    action: "android.intent.action.VIEW",
  packageName:"com.android.mediacenter",
  data: 'hwmediacenter://com.android.mediacenter/showH5?pver=121000000&portal=hwmusic&from=com.huawei.musicplatform.campaignh5&needback=0&channelid=1&url=https%3A%2F%2Fcampaign-music.hicloud.com%2Fcamp%2F248404751211917312%2Findex.html%3Fappsafearguments%3Dtrue%26activity%3Dtrue%26operator%3D8%26share%3Dtrue%26transparentstatusbar%3Dtrue%26hideactionbar%3Dtrue%26needback%3Dtrue'
   });
sleep (15000)
}catch(err){
    log(err)
    }
  


try{
//华为视频签到
app.startActivity({
  action: "android.intent.action.VIEW",
packageName:"com.huawei.himovie",
data: 'himovie://com.huawei.himovie/showcampaign?campaignid=himovie.fuliditu9'
 });
sleep (15000)
}catch(err){
    log(err)
    }
 
try{
 //收音机签到
app.startActivity({        
        action: "android.intent.action.VIEW",
               data: "hwfmradio://com.huawei.android.FMRadio/showH5?pver=121000000&portal=hwmusic&from=com.huawei.musicplatform.campaignh5&needback=0&channelid=1&url=https://campaign-music.hicloud.com/i_1622512710_d/camp/235840624979439616/index.html?appsafearguments=true&nolandscapte=true&activity=true&operator=f1&transparentstatusbar=true&hideactionbar=true&share=true&needback=true&originbrand=1",
                     packageName: "com.huawei.android.FMRadio"
               });
}catch(err){
    log(err)
    }



function 领会员(){
   
    sleep(1000);
   
    打开抽奖页面(免费领会员)
    sleep(3000);
    if(textContains("次抽奖机会").findOne(3000)){
        sleep(5000);
         click(500,1350)
        sleep(2000)
        click("去登录")
    }
    textContains("每天限").findOne ();
    sleep(5000);
    click(365,1475);
    while(1){
        if(textContains("还有0次抽中大奖的机会").exists()){
            sleep(3000);
            break;
        }
          if(text("领取").findOne (50)){
        back()
        }
        if(text("我的卡券").findOne (50)){
         back()
         }
    click(543,1193);
    sleep(1000);
    click(500,1800);
   
    }
   
}

function 听书会员(){

  sleep(1000);
  打开抽奖页面(领听书会员)
  sleep(3000);
  if(textContains("次抽奖机会").findOne(3000)){
      sleep(5000);
       click(500,1350)
      sleep(2000)
      click("去登录")
  }
    textContains("每天限").findOne ();
    sleep(5000);
    while(1){
        if(textContains("还有0次抽中大奖的机会").exists()){
            sleep(3000);
            break;
        }
        找色("#ff6962",[[-13,-33,"#fffeff"],[30,-32,"#ffffff"],[-3,-72,"#ff6962"],[-54,-158,"#b3b1fa"],[-145,-88,"#8d91ea"],[137,39,"#8d91ea"]],"领听书抽奖");
        找色("#e3ae8c",[[-37,-2,"#fbede4"],[-74,-9,"#fffefa"],[-102,-35,"#f6ceab"],[71,3,"#fefefe"],[-492,6,"#e2b8a0"],[-242,2,"#e2b8a0"]],"领听书继续抽奖");
    if(text("领取").findOne (50)){
        back()
        }
    }
   
}

function 领花币(){
  
    sleep(1000);
    打开抽奖页面(免费领花币)
    sleep(3000);
    if(textContains("次抽奖机会").findOne(3000)){
        sleep(5000);
         click(525,1977)
        sleep(2000)
        click("去登录")
    }
    textContains("每天限").findOne ();
    sleep(5000);
    while(1){
        if(textContains("还有0次抽中大奖的机会").exists()){
            sleep(3000);
            break;
        }
          if(text("领取").findOne (100)){
        back()
        }
        找色("#fcbc40",[[-17,-35,"#fef9fd"],[44,-31,"#fffefa"],[21,-37,"#e6b86b"],[-20,20,"#fffffd"],[-74,-243,"#1b1b1b"],[68,-272,"#00466a"]],"领花币抽奖");
        找色("#f67144",[[-1,-51,"#f67144"],[39,-13,"#ffffff"],[-22,-9,"#fffbf8"],[-94,-5,"#fffbf6"],[-299,-18,"#333333"],[-292,-58,"#e5e5e5"]],"领花币继续抽奖");
        click(525,1977)
    }
    
}

function 打开抽奖页面(活动名){
    console.log(活动名);
        app.startActivity({        
              action: "android.intent.action.VIEW",
                     data: "hwmediacenter://com.android.mediacenter/showH5?pver=121000000&portal=hwmusic&from=com.huawei.musicplatform.campaignh5&needback=0&channelid=1&url=https://campaign-music.hicloud.com/camp/"+活动名+"/index.html#/home?operator=8&needback=true&shared=true",
                           packageName: "com.android.mediacenter"
                     });
    }
function 关闭音乐() {
    
   // openAppSetting("com.android.mediacenter");
    while (!click("强行停止"));
    sleep (1000);
    while (!click("强行停止"));
    home();
    sleep (3000);
}
alert("卸载完成");
function 找色(颜色,各坐标颜色,日志){
   var img = captureScreen();
   var p = images.findMultiColors(img, 颜色,各坐标颜色)
   if(p){
       sleep (1000)
         console.log(日志);
       click(p.x, p.y);
       sleep(1000)
   }
     
   
}